package com.example.mymarket.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.mymarket.Menu.LeftMenu;
import com.example.mymarket.R;

import java.util.List;

public class LeftMenuAdapter extends BaseAdapter {
    private Context ctx;
    private List<LeftMenu> leftMenus;

    public LeftMenuAdapter(Context ctx, List<LeftMenu> leftMenus) {
        this.ctx = ctx;
        this.leftMenus = leftMenus;
    }

    @Override
    public int getCount() {
        return this.leftMenus.size();
    }

    @Override
    public Object getItem(int i) {
        return this.leftMenus.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null){
            view= LayoutInflater.from(this.ctx).inflate(R.layout.catalog_left_tem,null);
            viewHolder=new ViewHolder();
            viewHolder.catalog_left_item_line=view.findViewById(R.id.catalog_left_item_line);
            viewHolder.catalog_left_item_text=view.findViewById(R.id.catalog_left_item_text);
            view.setTag(viewHolder);
        } else  {
            viewHolder=(ViewHolder) view.getTag();
        }
        if (this.leftMenus.get(i).getChecked()){
            viewHolder.catalog_left_item_line.setVisibility(View.VISIBLE);
        } else {
            viewHolder.catalog_left_item_line.setVisibility(View.INVISIBLE);
        }
        viewHolder.catalog_left_item_text.setText(this.leftMenus.get(i).getName());
        return view;
    }

    static class ViewHolder{
        TextView catalog_left_item_line;
        TextView catalog_left_item_text;
    }
}
